/*! \file FileHandle.inl
 *	\brief
 *
 *	created:	2010/11/23
 *	created:	23:11:2010   10:15
 *	filename: 	C:\src\tactics-engine\libs\utils\unix\FileHandle.inl
 *	file path:	C:\src\tactics-engine\libs\utils
 *	file base: FileHandle
 *	file ext:	inl
 *	author:		Vitalii Trubchaninov
 *				vitalii.trubchaninov@ubisoft.com
 */

namespace tt{
namespace utils{

inline
FileHandle::FileHandle(int fileId)
: m_FileId(fileId)
{

}

inline
FileHandle::~FileHandle()
{
	if(Valid())
	{
		close(m_FileId);
		m_FileId = INVALID_FILEID_VALUE;
	}
}

inline
bool FileHandle::Valid() const
{
	return (m_FileId != 0) && (m_FileId != INVALID_FILEID_VALUE);
}

inline
void FileHandle::Reset( int fileId )
{
	FileHandle(fileId).Swap(*this);
}

inline
void FileHandle::Swap( FileHandle& other )
{
	std::swap(m_FileId, other.m_FileId);
}

inline
FileHandle::operator int() const
{
	return m_FileId;
}

inline
FileHandle::operator bool() const
{
	return Valid();
}

} //namespace utils
} //namespace tt
